package com.vitalfit.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class GatewayConfiguration {
    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
        return builder.routes()
                .route("user-service-route", r -> r.path("/users/**")
                        .filters(f -> f.rewritePath("/users/(?<segment>.*)", "/${segment}"))
                        .uri("lb://user-service"))
                .route("appointment-service-route", r -> r.path("/appointments/**")
                        .filters(f -> f.rewritePath("/appointments/(?<segment>.*)", "/${segment}"))
                        .uri("lb://appointment-service"))
                .route("food-service-route", r -> r.path("/foods/**")
                        .filters(f -> f.rewritePath("/foods/(?<segment>.*)", "/${segment}"))
                        .uri("lb://food-service"))
                .build();
    }
}